package distributedbank.requests;
import java.io.IOException;
import java.io.Serializable;
import distributedbank.responses.*;
import distributedbank.server.*;
import distributedbank.*;
/**
 * This is a request to deposit a certain amount (possibly negative) of cents
 * to a given account.
 */
public class DepositRequest extends GUIRequest {
	private static final long serialVersionUID = 8843448729613346938L;
	private int amount; // amount is the number of cents to deposit
    public DepositRequest(int branchId, int accountId, int transactionId,
                          int originatingClientId, int amount) {
        super(branchId, accountId, transactionId, originatingClientId);
        this.amount = amount;
    }
    public void runRequest(BankBranch bankBranch, Wrapper wrapper) 
                throws IOException {
        System.out.println("Depositing " + this.amount +
                           " to account " + this.accountId +
                           " at branch " + this.branchId);
        int balance = bankBranch.getAccount(this.accountId)
        				.deposit(this.amount, this.transactionId);
        Serializable message = new BalanceResponse(balance);
        wrapper.sendMessage(message, this.branchId, this.originatingClientId);
        }
}